package com.jrtc.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jrtc.base.entity.bo.Doctorservicedoctor;
import com.jrtc.base.config.dto.ResultDTO;
import com.jrtc.base.config.dto.ResultDTOBuilder;
import com.jrtc.service.DoctorservicedoctorService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 医生医事服务关联表(Doctorservicedoctor)表控制层
 *
 * @author makejava
 * @since 2022-03-21 17:19:03
 */
@RestController
@RequestMapping("serviceDoctor")
public class DoctorservicedoctorController {
    /**
     * 服务对象
     */
    @Resource
    private DoctorservicedoctorService doctorservicedoctorService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Doctorservicedoctor selectOne(Integer id) {
        return this.doctorservicedoctorService.queryById(id);
    }
    
    @RequestMapping("getDoctorServiceList")
    public ResultDTO getDoctorservicedoctorList(@RequestBody Doctorservicedoctor doctorservicedoctor)
    {
        IPage<Doctorservicedoctor> ipage = doctorservicedoctorService.queryDoctorservicedoctorList(doctorservicedoctor);
        return ResultDTOBuilder.success(ipage);
    }

    @RequestMapping("insertDoctorService")
    public ResultDTO insertDoctorservicedoctor(@RequestBody Doctorservicedoctor doctorservicedoctor)
    {
        Doctorservicedoctor tmpDoctorservicedoctor = doctorservicedoctorService.insert(doctorservicedoctor);
        if (tmpDoctorservicedoctor != null)
        {
           return ResultDTOBuilder.success("添加成功！");
        }
        return ResultDTOBuilder.failureMsg("添加失败！");
    }

    @RequestMapping("getDoctorServiceById")
    public ResultDTO getDoctorservicedoctorById(@RequestBody Map<String, Integer> map)
    {
        int doctorservicedoctorId = map.get("doctorservicedoctorId");
        Doctorservicedoctor doctorservicedoctor = doctorservicedoctorService.queryById(doctorservicedoctorId);
        if (doctorservicedoctor==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        return ResultDTOBuilder.success(doctorservicedoctor);
    }

    @RequestMapping("updateDoctorService")
    public ResultDTO updateDoctorservicedoctor(@RequestBody Doctorservicedoctor doctorservicedoctor)
    {
        if (doctorservicedoctor==null)
        {
            return ResultDTOBuilder.failureMsg("信息有误！");
        }
        if (doctorservicedoctorService.update(doctorservicedoctor)!=null)
        {
            return ResultDTOBuilder.success("修改信息成功！");
        }
        return ResultDTOBuilder.failureMsg("修改信息失败！");
    }
    
    @RequestMapping("deleteDoctorService")
    public ResultDTO deleteDoctorservicedoctor(@RequestBody Map<String,Integer> map)
    {
        int doctorservicedoctorId = map.get("doctorservicedoctorId");
        if (doctorservicedoctorService.deleteById(doctorservicedoctorId))
        {
            return ResultDTOBuilder.success("删除成功！");
        }
        return ResultDTOBuilder.failureMsg("删除失败！");
    }
}